public partial class Attendance : Form
    {
        public Attendance()
        {
            InitializeComponent();
        }

        private void Attendance_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'stafScheDataSet.Attendance' table. You can move, or remove it, as needed.
            this.attendanceTableAdapter.Fill(this.stafScheDataSet.Attendance);
            // TODO: This line of code loads data into the 'stafScheDataSet.Schedule' table. You can move, or remove it, as needed.
            this.scheduleTableAdapter.Fill(this.stafScheDataSet.Schedule);
            // TODO: This line of code loads data into the 'stafScheDataSet.AtteKind' table. You can move, or remove it, as needed.
            this.atteKindTableAdapter.Fill(this.stafScheDataSet.AtteKind);
            // TODO: This line of code loads data into the 'stafScheDataSet.Staff' table. You can move, or remove it, as needed.
            this.staffTableAdapter.Fill(this.stafScheDataSet.Staff);
            // TODO: This line of code loads data into the 'stafScheDataSet.Attendance' table. You can move, or remove it, as needed.
            this.attendanceTableAdapter.Fill(this.stafScheDataSet.Attendance);
            dataGridView1.AutoGenerateColumns = false;
        }

        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;
            //MessageBox.Show(dgv.CurrentCell.OwningColumn.Name);
            if (dgv.CurrentCell.OwningColumn.HeaderText == "StaffID")
            {
                ComboBox cbStaff = (ComboBox)e.Control;
                //cbStaff.SelectedIndexChanged += new EventHandler(cbStaff_SelectedIndexChanged);
                cbStaff.SelectionChangeCommitted += new EventHandler(cbStaff_SelectionChangeCommitted);
            }
        }

        void cbStaff_SelectionChangeCommitted(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            try
            {
                ComboBox cb = (ComboBox)sender;
                //MessageBox.Show(cb.Parent.Parent.GetType().Name);

                DataGridViewRow dgvr = dataGridView1.CurrentRow;
                DataGridViewComboBoxCell cbSche = (DataGridViewComboBoxCell)dgvr.Cells["scheIDDataGridViewTextBoxColumn"];
                //MessageBox.Show(dgvr.Cells[2].OwningColumn.Name);
                DataTable dt = this.stafScheDataSet.Schedule.Clone();
                this.stafScheDataSet.Schedule.Select("StaffID="
                    + cb.SelectedValue.ToString()).CopyToDataTable(dt, LoadOption.PreserveChanges);
                cbSche.DataSource = dt;
                cbSche.DisplayMember = "StartTime";
                cbSche.ValueMember = "ID";
                //this.scheduleBindingSource.Filter = "StaffID=" + cb.SelectedValue.ToString();
                //MessageBox.Show(cb.SelectedValue.ToString());
            }
            catch { }
        }

        void cbStaff_SelectedIndexChanged(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            ComboBox cb = (ComboBox)sender;
            DataGridViewRow dgvr = dataGridView1.CurrentRow;
            DataGridViewComboBoxCell cbSche = (DataGridViewComboBoxCell)dgvr.Cells["scheIDDataGridViewTextBoxColumn"];
            DataTable dt = this.stafScheDataSet.Schedule.Clone();
            //cbSche.Items.Add(
            cbSche.Items.Clear();
            foreach (DataRow dr in
            this.stafScheDataSet.Schedule.Select("StaffID="
                + cb.SelectedValue.ToString()))
            {
                dt.Rows.Add(dr.ItemArray);
                cbSche.Items.Add(dr["StartTime"].ToString());
            }
        }

        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
        {
            this.attendanceTableAdapter.Update(this.stafScheDataSet.Attendance);
        }

        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            foreach (DataGridViewRow dgvr in dataGridView1.Rows)
            {
                //DataGridViewRow dgvr = dataGridView1.CurrentRow;
                DataGridViewComboBoxCell cbStaff = (DataGridViewComboBoxCell)dgvr.Cells[1];
                DataGridViewComboBoxCell cbSche = (DataGridViewComboBoxCell)dgvr.Cells[2];
                try
                {
                    cbSche.DataSource = this.stafScheDataSet.Schedule.Select("StaffID="
                        + cbStaff.Value.ToString());
                    cbSche.DisplayMember = "StartTime";
                    cbSche.ValueMember = "ID";
                }
                catch { }
            }
        }

        private void Attendance_Activated(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(uc.User))
            {
                bindingNavigator1.Enabled = false;
                dataGridView1.ReadOnly = true;
            }
            else
            {
                bindingNavigator1.Enabled = true;
                dataGridView1.ReadOnly = false;
            }
        }
    }
